package main

import (
	"seichat/dao"
	"seichat/handler"
	"seichat/initialize"
	"seichat/service"
)

func main() {
	//初始化日志
	initialize.InitLogger()
	//初始化配置
	initialize.InitConfig()
	//初始化数据库
	db := initialize.InitDB()
	redis := initialize.InitRedis()
	//dao
	userDao := dao.NewUserDao(db)
	relationDao := dao.NewRelationDao(db)
	communityDao := dao.NewCommunityDao(db)
	messageDao := dao.NewMessageDao(redis)
	//svc
	userService := service.NewUserService(userDao, messageDao)
	relationService := service.NewRelationService(relationDao, userService)
	communityService := service.NewCommunityService(communityDao, relationService, userService)
	uploadSvc := service.NewUploadService("./asset/upload")
	inMemoryMessageService := service.NewInMemoryConnectionManager(messageDao, relationService)
	//handler
	userHandler := handler.NewUserHandler(userService)
	relationHandler := handler.NewRelationHandler(relationService)
	communityHandler := handler.NewCommunityHandler(communityService)
	uploadHandler := handler.NewUploadHandler(uploadSvc)
	messageHandler := handler.NewHandlerMessage(inMemoryMessageService)
	server := handler.Router(userHandler, relationHandler, communityHandler, uploadHandler, messageHandler)
	err := server.Run(":8000")
	if err != nil {
		panic(err)
	}
}
